# 数据抓取
# 方法A：使用Python requests + BeautifulSoup
import requests
from bs4 import BeautifulSoup
import time
import json


def extract_jdl_qa():
    base_url = "https://www.jdl.cn"
    headers = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36'
    }

    # 抓取帮助中心页面
    help_url = f"{base_url}/help"
    response = requests.get(help_url, headers=headers)
    soup = BeautifulSoup(response.content, 'html.parser')

    qa_pairs = []

    # 查找FAQ常见结构
    faq_sections = soup.find_all(['div', 'section'], class_=['faq', 'help-item', 'question'])

    for section in faq_sections:
        question = section.find(['h3', 'h4', 'strong'])
        answer = section.find(['p', 'div'], class_=['answer', 'content'])

        if question and answer:
            qa_pairs.append({
                'question': question.get_text().strip(),
                'answer': answer.get_text().strip(),
                'source': help_url
            })

    return qa_pairs